SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_Event]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_Event](
	[n4EventSN] [int] IDENTITY(1,1) NOT NULL,
	[dtEventStart] [datetime] NOT NULL,
	[dtEventEnd] [datetime] NOT NULL,
	[dtPublicationDate] [datetime] NULL,
	[strImageUrl] [varchar](1000) NOT NULL,
	[strBigImageUrl] [varchar](1000) NOT NULL,
	[strTitle] [nvarchar](200) NOT NULL,
	[strContent] [nvarchar](max) NOT NULL,
	[isShow] [bit] NOT NULL,
	[n4TotalCommentCount] [int] NULL,
	[n4ParticipationCount] [int] NULL,
	[n4UniqueUserCount] [int] NULL,
	[dtCreateDate] [datetime] NULL,
	[strManagerName] [nvarchar](50) NULL,
 CONSTRAINT [PK_TB_Event] PRIMARY KEY CLUSTERED 
(
	[n4EventSN] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_EventCommentWriter]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_EventCommentWriter](
	[n4EventUserSN] [int] IDENTITY(1,1) NOT NULL,
	[n4EventSN] [int] NOT NULL,
	[n4UserNo] [int] NOT NULL,
	[n4Count] [int] NOT NULL,
	[dtCreateDate] [datetime] NOT NULL,
	[dtModifyDate] [datetime] NOT NULL,
 CONSTRAINT [PK_TB_EventCommentWriter] PRIMARY KEY CLUSTERED 
(
	[n4EventSN] ASC,
	[n4UserNo] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_EventCommentWriter]') AND name = N'IX_TB_EventCommentWriter_n4Count')
CREATE NONCLUSTERED INDEX [IX_TB_EventCommentWriter_n4Count] ON [dbo].[TB_EventCommentWriter] 
(
	[n4EventSN] ASC,
	[n4Count] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_EventCommentWriter]') AND name = N'IX_TB_EventCommentWriter_UserNo_n4EventUserSN')
CREATE NONCLUSTERED INDEX [IX_TB_EventCommentWriter_UserNo_n4EventUserSN] ON [dbo].[TB_EventCommentWriter] 
(
	[n4UserNo] ASC,
	[n4EventUserSN] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TB_EventComment]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[TB_EventComment](
	[n4EventSN] [int] NOT NULL,
	[n4EventCommentSN] [int] IDENTITY(1,1) NOT NULL,
	[strComment] [nvarchar](2000) NOT NULL,
	[n4UserNo] [int] NOT NULL,
	[strUserID] [varchar](50) NOT NULL,
	[strUserName] [nvarchar](50) NULL,
	[dtCreateDate] [datetime] NOT NULL,
	[dtRemoveDate] [datetime] NULL,
	[IsRemove] [tinyint] NOT NULL,
	[strUserIP] [varchar](50) NOT NULL,
 CONSTRAINT [PK_TB_EventComment] PRIMARY KEY CLUSTERED 
(
	[n4EventSN] ASC,
	[n4EventCommentSN] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[TB_EventComment]') AND name = N'IX_TB_EventComment_n4EventSN_IsRemove_n4EventCommentSN')
CREATE NONCLUSTERED INDEX [IX_TB_EventComment_n4EventSN_IsRemove_n4EventCommentSN] ON [dbo].[TB_EventComment] 
(
	[n4EventSN] ASC,
	[IsRemove] ASC,
	[n4EventCommentSN] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
